# -- coding: utf-8 --

'''
继承
子类teacher、student继承父类person的方法，但此方法明显初始化的时候重复了很多
'''

# class Person:
#     def __init__(self,name,age):
#         self.name = name
#         self.age = age
#
#     def introduce(self):
#         print("name: %s" % self.name)
#         print("age: %s" % self.age)
#
# class Teacher(Person):
#     def __init__(self,name,age,salary):
#         self.name = name
#         self.age = age
#         self.salary = salary
#
#     def show_salary(self):
#         print("salary: %s" % self.salary)
#
#
# class Student(Person):
#     def __init__(self,name,age,grade):
#         self.name = name
#         self.age = age
#         self.grade = grade
#
#     def show_grade(self):
#         print("grade: %s" % self.grade)
#
#
# teacher = Teacher("tim","18","200")
# teacher.introduce()
# teacher.show_salary()
#
# student = Student("josh","20","87")
# student.introduce()
# student.show_grade()

'''
精简版继承父类初始化方法

'''

class Person:
    def __init__(self,name,age):
        self.name = name
        self.age = age

    def introduce(self):
        print("name: %s" % self.name)
        print("age: %s" % self.age)

class Teacher(Person):
    def __init__(self,name,age,salary):
        Person.__init__(self,name,age)  # 这样直接继承父类方法
        self.salary = salary

    def show_salary(self):
        print("salary: %s" % self.salary)

class Student(Person):
    def __init__(self,name,age,grade):
        Person.__init__(self,name,age)
        self.grade = grade

    def show_grade(self):
        print("grade: %s" % self.grade)

teacher = Teacher("tim","18","200")
teacher.introduce()
teacher.show_salary()

student = Student("josh","20","87")
student.introduce()
student.show_grade()

'''
多继承 意为继承两个类的方法
'''

class Father:
    def __init__(self,name):
        self.name = name

    def show_name(self):
        print(self.name)

class Mother:
    def __init__(self,age):
        self.age = age

    def show_age(self):
        print(self.age)

class Child(Father,Mother):
    def __init__(self,name,age,hobby):
        Father.__init__(self,name)
        Mother.__init__(self,age)
        self.hobby = hobby

    def show_hobby(self):
        print(self.hobby)


child = Child('tim','12','run')
child.show_name()
child.show_age()
child.show_hobby()